home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / cbm / 4787 < prev    next >
Encoding:
Text File  |  1996-08-05  |  3.1 KB  |  88 lines

  1. Path: islay.ssl.berkeley.edu!korpela
  2. From: korpela@islay.ssl.berkeley.edu (Eric J. Korpela)
  3. Newsgroups: comp.sys.cbm,gnu.gcc.help,comp.sys.atari.8bit
  4. Subject: Re: GNU C-compiler port to 6502
  5. Date: 30 Mar 1996 01:14:22 GMT
  6. Organization: Cal Berkeley-- Space Sciences Lab
  7. Message-ID: <4ji1te$dnk@agate.berkeley.edu>
  8. References: <4irqpb$7pc@esel.cosy.sbg.ac.at> <4jbmcf$733@news.iastate.edu> <4jgc70$lmt@dodo.cosy.sbg.ac.at>
  9. NNTP-Posting-Host: islay.ssl.berkeley.edu
  10.  
  11. In article <4jgc70$lmt@dodo.cosy.sbg.ac.at>,
  12. Gerhard Wesp <gwesp@dodo.cosy.sbg.ac.at> wrote:
  13. >
  14. >>  But the biggest choice of all is whether to let GCC manage the 6502
  15. >>registers directly, or to use a sort of ``virtual machine'' model on
  16. >>the 6502 that looks better to GCC (page zero registers, manipulated by
  17. >>simple bits of native code that GCC thinks are single instructions).
  18. >
  19. > Exactly such sort of thing I thought of. The code could be
  20. >implemented as macros and as subroutines for the more complex things
  21. >like multiplicatio, division, floating point ops etc. (or we use
  22. >pseudo ops triggered by a brk...)
  23.  
  24. The biggest problem with this is interfacing to the optimizer.  Suppose
  25. we design macros that do the instructions for our 32 bit machine with
  26. 8 32bit (zero page starting at $80) pseudoregisters.  Let's run through 
  27. a two instruction example.
  28.  
  29. register int r0 = (unsigned short)mem1 & (int)mem2;
  30.  
  31. In our macro language, gcc might compile that as
  32.  
  33. ldsz _mem1,%r0
  34. andl %r0,_mem2,%r0
  35.  
  36. Our macros are 
  37.  
  38. ldsz _mem1,%r0  defined as
  39.         LDX     #1
  40.         LDY     #0
  41. 0:      LDA     _mem1,X
  42.         STA     $80,X
  43.         STY     $82,X
  44.         DEX
  45.         BPL     0b
  46.  
  47. andl %r0,_mem2,%r0 defined as
  48.         LDX     #3
  49. 0:      LDA     _mem2,X
  50.         AND     $80,X
  51.         STA     $80,X
  52.         DEX
  53.         BPL     0b
  54.  
  55. Since gcc wouldn't know anything about the internal structure of the macros, 
  56. it would just concatanate the two instruction macros.  Whereas a native 65C02 
  57. C compiler outputting real 65C02 instructions could notice that the LDX #3 
  58. could be changed to a LDX #1 and optimize the instruction sequence.  An even 
  59. better optimization would be to combine the two into one loop like this:  
  60.  
  61.         LDX     #1
  62.         LDY     #0
  63. 0:      LDA     _mem1,X
  64.         AND     _mem2,X
  65.         STA     $80,X
  66.         STY     $82,X
  67.         DEX
  68.         BPL     0b
  69.  
  70. That's a reduction from 32 to 14 cycles (incorrectly assuming 1/instruction)
  71. in execution time and a reduction in size from 26 to 17 bytes in size.  On
  72. a 6502 both of those are important things. (64K address space, 1-2 Mhz)
  73.  
  74. A native 6502 compiler could do that kind of optimization, our "macro" 
  75. compiler couldn't without an additional optimizer.  My guess is that the 
  76. optimizer would be as hard to write as a native 6502 C compiler.
  77.  
  78. IMHO, the answer is "Yes, it would be possible to alter gcc to output a
  79. pseudocode that could be compiled to 6502 instructions, but it would be
  80. hard to optimize the resulting code."
  81.  
  82. Eric
  83. -- 
  84. Eric Korpela                        |  An object at rest can never be
  85. korpela@ssl.berkeley.edu            |  stopped.
  86. <a href="http://www.cs.indiana.edu/finger/mofo.ssl.berkeley.edu/korpela/w">
  87. Click here for more info.</a>
  88.